<?php
/**
 * 分类目录附加表单项 
 * @package WordPress
 * @subpackage wheatv
 */


//add extra fields to category edit form hook
add_action ( 'edit_category_form_fields', 'extra_category_fields');

//add extra fields to category edit form callback function

function extra_category_fields( $tag ) {    //check for existing featured ID
    $t_id = $tag->term_id;
    $cat_meta = get_option( "category_$t_id");
?>

<tr class="form-field">
<th scope="row" valign="top"><label for="Cat_meta[img]"><?php _e('分类目录缩略图'); ?></label></th>
<td>
<input type="text" name="Cat_meta[img]" id="Cat_meta[img]" size="3" style="width:60%;" value="<?php echo $cat_meta['img'] ? $cat_meta['img'] : ''; ?>" /><br />
            <span class="description"><?php _e('分类目录缩略图: 输入图片完整链接，必须带http://，最佳尺寸是95X88'); ?></span>
        </td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="Cat_meta[status]"><?php _e('是否显示分类简介'); ?></label></th>
<td>
<select name="Cat_meta[status]" id="Cat_meta[status]">
  <option value="1" <?php if($cat_meta['status']==1)echo'selected="selected"'; ?>>显示</option>
  <option value="0" <?php if($cat_meta['status']==0)echo'selected="selected"'; ?>>不显示</option>
</select>
</td>
</tr>
<?php
}
?>
<?php
// save extra category extra fields hook
add_action ( 'edited_category', 'save_extra_category_fileds');
   // save extra category extra fields callback function
function save_extra_category_fileds( $term_id ) {
    if ( isset( $_POST['Cat_meta'] ) ) {
        $t_id = $term_id;
        $cat_meta = get_option( "category_$t_id");
        $cat_keys = array_keys($_POST['Cat_meta']);
            foreach ($cat_keys as $key){
            if (isset($_POST['Cat_meta'][$key])){
               $cat_meta[$key] = $_POST['Cat_meta'][$key];
            }
        }

        //save the option array
        update_option( "category_$t_id", $cat_meta );
    }
}
?>